<!DOCTYPE html>
<html>
<head>
    <title>今日任务</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="description" content="木兰湾管理系统">
    <script type="text/javascript" src="../../static/include/header-css.js"></script>
</head>
<body>
<form id="search-form">
    <div class="weui-cell mulanbay_select-before ">
        <div class="weui-cell__hd" >
            <label class="weui-label">日期</label>
        </div>
        <div class="weui-cell__bd">
            <input class="weui-input" id="calendarDate" name="calendarDate" type="text">
        </div>
        <div class="weui-cell__hd">
            <a href="javascript:searchData()" class="weui-btn weui-btn_mini weui-btn_primary">查询</a>
        </div>
    </div>
</form>
<div class="weui-form-preview__ft">
    <a class="weui-form-preview__btn weui-form-preview__btn_primary" href="javascript:getCalendarToday()">今天</a>
    <a class="weui-form-preview__btn weui-form-preview__btn_primary" href="javascript:getCalendarDev(-1)">前一天</a>
    <a class="weui-form-preview__btn weui-form-preview__btn_primary" href="javascript:getCalendarDev(1)">后一天</a>
</div>
<!--下边框-->
<div  class="border-b w" ></div>
<!--列表数据显示-->
<div id="dataContent"></div>
<div class="button_sp_area" align="center">
    <a href="javascript:refreshData();" class="weui-btn weui-btn_mini weui-btn_primary">刷新</a>
    <a href="javascript:scroll(0,0);" class="weui-btn weui-btn_mini weui-btn_primary">返回顶部</a>
    <a href="javascript:sendCalendarMessage();" class="weui-btn weui-btn_mini weui-btn_primary">发送给我</a>
</div>
<br>
<script type="text/javascript" src="../../static/include/footer-js.js"></script>
<script>
    $(function() {
        $("#calendarDate").calendar({
            //初始值无效
            value: [getNowDateString()],
            dateFormat: 'yyyy-mm-dd',
            onChange: function (p, values, displayValues) {
                if(values!=$('#calendarDate').val()){
                    document.getElementById('calendarDate').value=values;
                    getData();
                }
            }
        });
        $('#calendarDate').val(getNowDateString());
        getData();
    });
    function getCalendarToday() {
        $('#calendarDate').val(getNowDateString());
        getData();
    }
    function getCalendarDev(n) {
        var calendarDate = $('#calendarDate').val();
        calendarDate = getDayByDate(n,calendarDate);
        $('#calendarDate').val(calendarDate);
        getData();
    }
    function sendCalendarMessage() {
        var calendarDate = $('#calendarDate').val();
        $.confirm("您是否要把该天的任务列表发送到我的消息?<br>（消息接收模式以个人配置的短信或者微信形式）", "确认发送?", function() {
            var url='/userCalendar/sendCalendarMessage';
            var para ={
                date:calendarDate,
                calendarDate:calendarDate
            };
            doAjax(para,url,'POST',true,function() {

            });
        }, function() {
            $.toptip('已取消', 'warning');
        });
    }
    function refreshData() {
        getData();
        //返回顶部
        scroll(0,0);
    }
    function getDivId(id) {
        return 'TodayCalendar'+id;
    }
    function getData() {
        scroll(0,0);
        var calendarDate = $('#calendarDate').val();
        var para = {
            startDate:calendarDate,
            endDate:calendarDate,
            needFinished: false,
            needPeriod:true,
            needBudget: true,
            needTreatDrug: true,
            needBandLog:false
        };
        var url='/userCalendar/getList';
        doAjax(para,url,'GET',false,function(data){
            var html='';
            for (var i = 0; i < data.length; i++) {
                var rowData =data[i];
                var title =data[i].title;
                if(data[i].delayCounts>2){
                    title='<font color="red">'+data[i].title+'</font>';
                }
                title=(i+1)+'.'+title;
                html+='<div id="'+getDivId(rowData.id)+'">';
                html+='<div class="weui-form-preview">';
                html+='    <a class="weui-cell  weui-cell_access weui-cell_example" href="javascript:showEdit('+rowData.id+');">\n';
                // 后期根据餐次类型来显示
                var pr =rowData.sourceType.toLowerCase();
                var pic = '<img src="../../static/image/'+pr+'.png">';
                html+='        <div class="weui-cell__hd">'+pic+'</div>\n';
                html+='        <div class="weui-cell__bd">\n';
                html+='<label class="weui-form-preview__label">'+title+'</label>';
                html+='        </div>\n';
                html+='        <div class="weui-cell__ft">延迟次数:'+rowData.delayCounts+'</div>\n';
                html+='    </a>\n';
                html+='    <div class="weui-form-preview__bd">\n';
                html+='        <div class="weui-form-preview__item">\n';
                html+='            <label class="weui-form-preview__label">日历时间</label>\n';
                if(rowData.allDay){
                    html+='            <span class="weui-form-preview__value">全天日历</span>\n';
                }else{
                    var ds = rowData.bussDay.substring(11,16);
                    html+='            <span class="weui-form-preview__value">'+ds+'</span>\n';
                }
                html+='        </div>\n';
                html+='        <div class="weui-form-preview__item">\n';
                html+='            <label class="weui-form-preview__label">失效时间</label>\n';
                html+='            <span class="weui-form-preview__value">'+rowData.expireTime+'</span>\n';
                html+='        </div>\n';
                html+='        <div class="weui-form-preview__item">\n';
                html+='            <label class="weui-form-preview__label">创建时间</label>\n';
                html+='            <span class="weui-form-preview__value">'+rowData.createdTime+'</span>\n';
                html+='        </div>\n';
                html+='        <div class="weui-form-preview__item">\n';
                html+='            <label class="weui-form-preview__label">行程来源</label>\n';
                html+='            <span class="weui-form-preview__value">'+rowData.sourceTypeName+'</span>\n';
                html+='        </div>\n';
                html+='        <div class="weui-form-preview__item">\n';
                html+='            <label class="weui-form-preview__label">行程详情</label>\n';
                html+='            <span class="weui-form-preview__value mulanbay-dark-font">'+rowData.content+'</span>\n';
                html+='        </div>\n';
                html+='    </div>\n';
                if(false==rowData.readOnly){
                    html+='    <div class="weui-form-preview__ft">\n';
                    html+='        <a class="weui-form-preview__btn weui-form-preview__btn_primary" href="javascript:finishUserCalendar('+rowData.id+');">完成</a>\n';
                    html+='    </div>\n';
                }
                html+='</div>\n';
                html+='</div>\n';
                html+='<br>\n';
            }
            document.getElementById('dataContent').innerHTML = html;
        });
    }
    function finishUserCalendar(id) {
        $.confirm("您是否要把该条行程手动设置为完成?", "确认完成?", function() {
            var url='/userCalendar/finish';
            var para ={
                id:id
            };
            doAjax(para,url,'POST',false,function() {
                //直接把该节点删除
                setElementInnerHTML(getDivId(id),'');
            });
        }, function() {
            $.toptip('已取消', 'warning');
        });
    }
</script>
</body>
</html>